package com.youyiwen.Mapper;

import com.youyiwen.Bean.Message;
import com.youyiwen.dto.MessageDTO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Author: zhaoyang
 * @Date: 2021/04/15
 */
@Mapper
public interface MessageMapper {

    @Insert("insert into message values (#{id},#{sender},#{receiver},#{gmtCreate},#{content},#{hasRead},#{forUser})")
    public void insertMsg(Message message);

    public List<Message> selectMessages(@Param("sender") String sender,
                                        @Param("receiver")String receiver,
                                        @Param("forUser")String forUser);

    @Select("select count(1) from message where receiver = #{receiver} and has_read = 0 and for_user = #{receiver}")
    public Integer selectMessageCount(String receiver);

    @Update("update message set has_read = 1 where sender = #{sender} and receiver = #{receiver} and for_user = #{receiver}")
    public void updateMessageCount(String sender,String receiver);


}
